from rest_framework import serializers
from .models import Banner,Nav

class BannerModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = Banner
        fields = ["image","link","is_http"]

'''
这个位置纠结过子数据是如何得到的，首先models里面的pid是自外键 所以可以由son作为关联，
然后通过序列化器嵌套来完成全部数据的展示，否则只显示id
'''
class SonNavModelSerializer(serializers.ModelSerializer):

     class Meta:
         model = Nav
         fields = ["name","icon","link","is_http"]

class NavModelSerializer(serializers.ModelSerializer):

    son = SonNavModelSerializer(many=True)

    class Meta:
        model = Nav
        fields = ["name","icon","link","is_http","son"]